package com.cs.springmvc.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.CancellableFormController;

import com.cs.springmvc.model.UserModel;

/**
 * @author Sam.Lee
 * @version Created：Feb 5, 2013 11:33:58 AM
 */
public class CanCancelRegisterSimpleFormController extends
		CancellableFormController {

	public CanCancelRegisterSimpleFormController() {
		setCommandClass(UserModel.class); // 设置命令对象实现类
		setCommandName("user");// 设置命令对象的名字
	}

	// form object 表单对象，提供展示表单时的表单数据（使用commandName放入请求）
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		UserModel user = new UserModel();
		user.setUsername("please input username...");
		return user;
	}

	// 提供展示表单时需要的一些其他数据
	protected Map referenceData(HttpServletRequest request) throws Exception {
		Map map = new HashMap();
		map.put("cityList", Arrays.asList("jiangsu", "beijing", "shanghai"));
		return map;
	}

	protected void doSubmitAction(Object command) throws Exception {
		UserModel user = (UserModel) command;
		System.out.println(user);
	}

	protected ModelAndView onCancel(Object command) throws Exception {
		UserModel user = (UserModel) command;
		// TODO 调用业务对象处理
		System.out.println(user);
		return super.onCancel(command);
	}

}
